(module list-index (lib "eopl.ss" "eopl")
  (provide list-index)
  
;;1.22
;; list-index: Symbol * List -> Number / Boolen
;; usage: (list-index pred lst)
;; produces: return the 0-based position of the first element of lst that satisfies the predicate pred. If no element of lst satisfies the ;; ;;    predicate, then list-index returns #f

;; examples:
;; (list-index number? '(a b 1 2)) ==> 2
;; (list-index symbol? '(a b 1 2)) ==> 0
;; (list-index symbol? '(12 (a c) 5) ) ==> #f


(define (list-index pred lst)
  (cond
    ((null? lst) #f)
    ((not (pred (car lst))) (list-help pred (cdr lst) 0))
    (else 0)
   )
  )

 

(define (list-help pred lst n)
 (cond
  ((null? lst) #f)
  ((not (pred (car lst))) (list-help pred (cdr lst) (+ 1 n)))
  (else (+ n 1))
  )
 )

 

(list-index number? '(a b 1 2))
(list-index symbol? '(a b 1 2))
(list-index symbol? '(12 (a c) 5) )

)
